package com.keshan.controller;

import com.keshan.utils.DateUtil;
import com.keshan.pojo.Location;
import com.keshan.pojo.LocationJson;
import com.keshan.utils.Msg;
import com.keshan.service.LocationServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author keshan
 * @date 2022/10/21 - 19:12
 */
@CrossOrigin
@Controller
@RequestMapping("/location")
public class LocationController {
    @Autowired
    LocationServices locationServices;

    @RequestMapping("/insertlocation")
    @ResponseBody
    public Msg insertBySelectiveToLocation(@RequestBody LocationJson locationJson){
        Location location =new Location();
        location.setAddress(locationJson.getAddress());
        location.setCity(locationJson.getCity());
        location.setDeviceType(locationJson.getDevice_type());
        location.setImei(locationJson.getImei());
        location.setIsReply(locationJson.getIs_reply());
        location.setIsTrack(locationJson.getIs_track());
        location.setLat(locationJson.getLat());
        location.setLon(locationJson.getLon());
        location.setTimeBegin(DateUtil.StringToDate(locationJson.getTime_begin_str()));
        location.setType(locationJson.getType());
        int result = locationServices.insertBySelectiveLocation(location);
        return Msg.success().add("result",result);
    }
}
